﻿using System;
using System.Net;
using System.Windows.Forms;
using System.Web;

namespace BugClient
{
    public partial class CloseForm : Form
    {
        WebClient web;
        string url;
        string token;
        string bugID;

        public CloseForm(WebClient web, string url, string token, string bugID)
        {
            InitializeComponent();

            Text = "关闭-" + bugID;
            this.web = web;
            this.url = url;
            this.token = token;
            this.bugID = bugID;
        }

        private async void commitButton_Click(object sender, EventArgs e)
        {
            if (web.IsBusy)
                return;
            string response;
            try
            {
                response = await web.UploadStringTaskAsync(url + "/close", string.Format("bug={0}&comment={1}&token={2}", bugID, HttpUtility.UrlEncode(commentBox.Text), token));
            }
            catch (WebException ex)
            {
                MessageBox.Show("连接服务器失败：" + ex.Message);
                return;
            }
            if (string.IsNullOrEmpty(response))
            {
                MessageBox.Show("关闭失败");
                return;
            }
            DialogResult = DialogResult.OK;
            Dispose();
            Close();
        }
    }
}
